<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>前置机告警门限设置</title>
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/static/jquery-easyui-1.3.5/themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/static/jquery-easyui-1.3.5/themes/icon.css">
<script type="text/javascript" src="${pageContext.request.contextPath}/static/jquery-easyui-1.3.5/jquery.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/static/jquery-easyui-1.3.5/jquery.easyui.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/static/jquery-easyui-1.3.5/locale/easyui-lang-zh_CN.js"></script>
<script type="text/javascript">

	function openAlarmThresholdModifyDialog(){
		 var selectedRows=$("#dg").datagrid("getSelections");
		 console.log(selectedRows);
		 if(selectedRows.length < 1){
			 $.messager.alert("系统提示","请选择需要编辑的数据！");
			 return;
		 }
		 var row=selectedRows[0];
		 $("#dlg").dialog("open").dialog("setTitle", "编辑告警门限信息");
		 $("#fm").form("load", row);
		 $("#flag").val(2);
		 $("#frontProcessorId").attr("readonly",true);
		 $("#serverId").attr("readonly",true);
		 /* for (var i = 0; i < selectedRows.length; i++) {
			 
		 } */
		 /* $("#packetLossAlarmThreshold").attr("readonly",true); */
	}
	
	function saveAlarmThreshold(){
		
		/* $("#fm").form("submit",{
			url:"${pageContext.request.contextPath}/alarmThreshold/saveFront.do",
			onSubmit:function(){
				return $(this).form("validate");
			},
			success:function(result){
				var result=eval('('+result+')');
				if(result.success){
					$.messager.alert("系统提示","保存成功！");
					resetValue();
					$("#dlg").dialog("close");
					$("#dg").datagrid("reload");
				}else{
					$.messager.alert("系统提示","保存失败！");
					return;
				}
			}
		 });
		 */
		
		var checked = $('#dg').datagrid('getChecked');

		var frontProcessorCpuThreshold = $('#frontProcessorCpuThreshold').val();
		var frontProcessorMemoryThreshold = $('#frontProcessorMemoryThreshold').val();
		var frontProcessorHardDiskThreshold = $('#frontProcessorHardDiskThreshold').val();
		 
		for (var i = 0; i < checked.length; i++) {

			$.post("${pageContext.request.contextPath}/alarmThreshold/saveFrontAlarm.do", {
				frontProcessorId: checked[i].frontProcessorId,
				frontProcessorCpuThreshold: frontProcessorCpuThreshold,
				frontProcessorMemoryThreshold: frontProcessorMemoryThreshold,
				frontProcessorHardDiskThreshold: frontProcessorHardDiskThreshold,
				flag: 2
			}, function(result) {
				/* if(result.success){
					
				}else{
					$.messager.alert("系统提示","保存失败！");
					return;
				} */
			}, "json");
			
		}

		$.messager.alert("系统提示","保存成功！");
		resetValue();
		$("#dlg").dialog("close");
		$("#dg").datagrid("reload");
	}
	
	function checkData(){
		var flag=$("#flag").val();
		if(flag==1){
		}else{
			saveAlarmThreshold();
		}
	}
	
	function resetValue(){
		 $("#alarmThresholdId").val("");
		 $("#serverId").val("");
		 $("#frontProcessorId").val("");
		 $("#cpuUsageThreshold").val("");
		 $("#memoryUsageThreshold").val("");
		 $("#harddiskUsageThreshold").val("");
 		 $("#packetLossAlarmThreshold").val("");
	 	 $("#frontProcessorCpuThreshold").val("");
		 $("#frontProcessorMemoryThreshold").val("");
		 $("#frontProcessorHardDiskThreshold").val("");
	}
	
	function closeAlarmThresholdDialog(){
		 $("#dlg").dialog("close");
		 resetValue();
	}
	
	function formatSuffix(value) {
		return value+"%";
	}
</script>
</head>
<body style="margin: 1px">
<table id="dg" title="前置机告警门限设置" class="easyui-datagrid" fitColumns="false" pagination="true" rownumbers="true"  pageSize="100" pageList="[100,200,300,400,500]"
   url="${pageContext.request.contextPath}/alarmThreshold/list.do" fit="true" toolbar="#tb" singleSelect="true">
   <thead>
   	<tr>
   		<th field="cb" checkbox="true" align="center"></th>
   		<!-- <th field="alarmThresholdId" width="150" align="center">alarmThresholdId</th> -->
   		<!-- <th field="serverId" width="150" align="center">serverId</th> -->
   		<th field="frontProcessorId" width="150" align="center" >前置机ID</th>
   		<th field="siteName" width="200" align="center" >前置机名</th>
   		<!-- <th field="cpuUsageThreshold" width="150" align="center" >服务器CPU使用率门限</th>
   		<th field="memoryUsageThreshold" width="150" align="center" >服务器内存使用率门限</th>
   		<th field="harddiskUsageThreshold" width="150" align="center" >服务器硬盘使用率门限</th> -->
   		<th field="frontProcessorCpuThreshold" width="150" align="center" >前置机CPU使用率门限</th>
   		<th field="frontProcessorMemoryThreshold" width="150" align="center" >前置机内存使用率门限</th>
   		<th field="frontProcessorHardDiskThreshold" width="150" align="center" >前置机硬盘使用率门限</th>
   		<!-- <th field="packetLossAlarmThreshold" width="110" align="center" >丢包率门限</th> -->
   	</tr>
   </thead>
 </table>
 <div id="tb">
 	<div>
 	<c:if test="${currentMemberShip.group.name=='管理员' }">
 		<a href="javascript:openAlarmThresholdModifyDialog()" class="easyui-linkbutton" iconCls="icon-edit" plain="true">修改</a>
 	</c:if>
 	</div>
 </div>
 
 <div id="dlg" class="easyui-dialog" style="width:620px;height:350px;padding: 10px 20px" closed="true" buttons="#dlg-buttons">
   
   <form id="fm" method="post">
   	<table cellspacing="8px">
   		<tr style="visibility:hidden">
   			<td>前置机ID：</td>
   			<td><input type="text" id="frontProcessorId" name="frontProcessorId" class="easyui-validatebox" required="true"/></td>
   			<!-- <td>&nbsp;&nbsp;&nbsp;&nbsp;</td> -->
   			<!-- <td>serverId</td>
   			<td><input type="text" id="serverId" name="serverId" class="easyui-validatebox" required="true"/></td> -->
   		</tr>
   		<!-- <tr>
   			<td>服务器CPU使用率门限：</td>
   			<td><input type="text" id="cpuUsageThreshold" name="cpuUsageThreshold" class="easyui-validatebox" required="true"/></td>
   			<td>&nbsp;&nbsp;&nbsp;&nbsp;</td>
   			<td>服务器内存使用率门限：</td>
   			<td><input type="text" id="memoryUsageThreshold" name="memoryUsageThreshold" class="easyui-validatebox" required="true"/></td>
   		</tr> -->
   		
   		<tr>
   			<!-- <td>服务器硬盘使用率门限：</td>
   			<td><input type="text" id="harddiskUsageThreshold" name="harddiskUsageThreshold" class="easyui-validatebox" required="true"/></td> -->
   			<!-- <td>&nbsp;&nbsp;&nbsp;&nbsp;</td> -->
   			<td>前置机CPU使用率门限：</td>
   			<td><input type="text" id="frontProcessorCpuThreshold" name="frontProcessorCpuThreshold" class="easyui-validatebox" required="true"/></td>
   			<td>&nbsp;&nbsp;&nbsp;&nbsp;</td>
   			<td>前置机内存使用率门限：</td>
   			<td><input type="text" id="frontProcessorMemoryThreshold" name="frontProcessorMemoryThreshold" class="easyui-validatebox" required="true"/></td>
   			<!-- <td>packetLossAlarmThreshold：</td>
   			<td><input type="text" id="packetLossAlarmThreshold" name="packetLossAlarmThreshold" class="easyui-validatebox" required="true"/>
   				<input type="hidden" id="flag" name="flag"/>
   			</td> -->
   		</tr>
   		<tr>
   			<!-- <td>前置机内存使用率门限：</td>
   			<td><input type="text" id="frontProcessorMemoryThreshold" name="frontProcessorMemoryThreshold" class="easyui-validatebox" required="true"/></td>
   			<td>&nbsp;&nbsp;&nbsp;&nbsp;</td> -->
   			<td>前置机硬盘使用率门限：</td>
   			<td><input type="text" id="frontProcessorHardDiskThreshold" name="frontProcessorHardDiskThreshold" class="easyui-validatebox" required="true"/></td>
   			<input type="hidden" id="flag" name="flag"/>
   		</tr>
   		
   	</table>
   </form>
 </div>
 
 <div id="dlg-buttons">
 	<a href="javascript:checkData()" class="easyui-linkbutton" iconCls="icon-ok">保存</a>
 	<a href="javascript:closeAlarmThresholdDialog()" class="easyui-linkbutton" iconCls="icon-cancel">关闭</a>
 </div>
 
</body>
</html>